﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace WebDesign.maneger
{
    public partial class TermList : System.Web.UI.Page
    {
        SqlClass scl = new SqlClass();
        public int[] array = new int[500];

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                scl.BindGridView("select TermName,Teacher,StartDate,DaysNum,Price,SessionNum,Expr from Termtbl", gvTermList);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            for (int k = 0; k < gvTermList.Rows.Count; k++)
            {
                array[k] = 0;
            }
            for (int k = 0; k < gvTermList.Rows.Count; k++)
            {
                CheckBox chk1 = new CheckBox();
                chk1 = (CheckBox)gvTermList.Rows[k].Cells[7].FindControl("ChkTerm");
                if (chk1.Checked == true)

                    array[k] = 1;
                else
                    array[k] = 0;
                


            }
            for (int i = 0; i < gvTermList.Rows.Count; i++)
            {
                if (array[i] == 1)
                {
                    scl.Command("delete from Termtbl where TermName=N'" + gvTermList.Rows[i].Cells[0].Text + "'");
                }
            }
            scl.BindGridView("select TermName,Teacher,StartDate,DaysNum,Price,SessionNum,Expr from Termtbl", gvTermList);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string chk = scl.checkCommand(" select TermId from Termtbl where TermName='" + txtTermName.Text + "'");
            if (chk != "")
            {
                lblPayam.Text = " این دوره قبلا ثبت شده است.";

            }
            else
            {
                SqlCommand sc = new SqlCommand();
                sc.Parameters.AddWithValue("@Tname", txtTermName.Text);
                sc.Parameters.AddWithValue("@Teacher", txtTeacher.Text);
                sc.Parameters.AddWithValue("@start", txtStartDate.Text);
                sc.Parameters.AddWithValue("@days", txtDate.Text);
                sc.Parameters.AddWithValue("@price", txtPrice.Text);
                sc.Parameters.AddWithValue("@SessonNum", txtُSessinNum.Text);
                sc.Parameters.AddWithValue("@exp", txtExpr.Text);
                scl.UseStoredProcedure("SaveTerm", sc);
                lblPayam.Text = " ثبت با موفقیت انجام شد.";
                scl.BindGridView("select TermName,Teacher,StartDate,DaysNum,Price,SessionNum,Expr from Termtbl", gvTermList);


            }

        }
    }
}








